package com.example.demo.service;

import com.example.demo.mapper.FightMapper;
import com.example.demo.mapper.ViewCityfightMapper;
import com.example.demo.pojo.Fight;
import com.example.demo.pojo.ViewCityfight;
import com.example.demo.pojo.ViewCityfightExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class FightServiceImpl implements FightService{
    @Resource
    FightMapper mapper1;
    @Resource
    ViewCityfightMapper mapper2;

    @Override
    public PageInfo<ViewCityfight> getSelectByFight(Integer departureid, Integer arrivalid, Integer pageNum, Integer pageSize) {
        PageHelper.orderBy("departuretime");
        PageHelper.startPage(pageNum,pageSize);
        ViewCityfightExample example=new ViewCityfightExample();
        ViewCityfightExample.Criteria criteria=example.createCriteria();
        if(departureid!=0){
            criteria.andDeparturecityEqualTo(departureid);
        }
        if(arrivalid!=0){
            criteria.andArrivalcityEqualTo(arrivalid);
        }
        PageInfo<ViewCityfight> pageInfo=new PageInfo<>(mapper2.selectByExample(example));
        return pageInfo;
    }

    @Override
    public int getInsert(Fight fight) {
        return mapper1.insertSelective(fight);
    }
}
